package com.xiaohao.server.parkmap.service;

import com.xiaohao.server.parkmap.entity.Complaint;
import com.xiaohao.server.parkmap.mapper.ComplaintMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Objects;

@Service
public class ComplaintService {
    @Autowired
    private ComplaintMapper complaintMapper;

    public Integer save(Complaint complaint) {
        if (Objects.nonNull(complaint) && Objects.nonNull(complaint.getId())) {
            return complaintMapper.updateById(complaint);
        } else {
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            complaint.setDate(timestamp);
            return complaintMapper.insert(complaint);
        }
    }
}
